﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiC3DProgressBarForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands;

internal class CUiC3DProgressBarForm : TxForm
{
  private CApC3DManagerApp m_generatorApp;
  private IContainer components;
  private Button m_cancel;
  private TxProgressBar m_progressBar;

  internal event CUiC3DProgressBarForm.CUiC3DProgressBarForm_ProcessCanceledEventHandler ProcessCanceled;

  internal event CUiC3DProgressBarForm.CUiC3DProgressBarForm_StartProcessEventHandler StartProcess;

  internal CUiC3DProgressBarForm()
  {
    this.InitializeComponent();
    ((Form) this).StartPosition = FormStartPosition.CenterParent;
    this.ShouldAutoPosition = false;
  }

  internal void Initialize(CApC3DManagerApp app, int stepNumber)
  {
    this.m_generatorApp = app;
    ((ProgressBar) this.m_progressBar).Value = 0;
    ((ProgressBar) this.m_progressBar).Minimum = 0;
    ((ProgressBar) this.m_progressBar).Maximum = stepNumber * 10;
    ((ProgressBar) this.m_progressBar).Step = 10;
    this.m_generatorApp.IncreaseProgressBar += new CApC3DManagerApp.CApC3DGeneratorApp_IncreaseProgressBarEventHandler(this.IncreaseProgressBar);
  }

  private void IncreaseProgressBar(object sender, EventArgs e)
  {
    ((ProgressBar) this.m_progressBar).PerformStep();
  }

  private void m_cancel_Click(object sender, EventArgs e)
  {
    ((Form) this).DialogResult = DialogResult.Cancel;
    this.ProcessCanceled((object) this, new EventArgs());
  }

  private void CUiC3DProgressBarForm_Shown(object sender, EventArgs e)
  {
    try
    {
      ((Control) this).Refresh();
      Application.DoEvents();
      ((Form) this).DialogResult = DialogResult.OK;
      this.StartProcess((object) this, new EventArgs());
    }
    catch (COMException ex)
    {
      ((Form) this).DialogResult = DialogResult.Abort;
      new TxErrorViewer().ShoweMSExceptionInfo((Exception) ex);
    }
    catch (Exception ex)
    {
      ((Form) this).DialogResult = DialogResult.Abort;
      string str = CApC3DUtils.GetResourceManager().GetString("CREATE_3D_DOCUMENTATION_CMD_NAME");
      int num = (int) TxMessageBox.Show(ex.Message, str, MessageBoxButtons.OK, MessageBoxIcon.Hand);
    }
  }

  private void CUiC3DProgressBarForm_FormClosing(object sender, FormClosingEventArgs e)
  {
    this.m_generatorApp.IncreaseProgressBar -= new CApC3DManagerApp.CApC3DGeneratorApp_IncreaseProgressBarEventHandler(this.IncreaseProgressBar);
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiC3DProgressBarForm));
    this.m_cancel = new Button();
    this.m_progressBar = new TxProgressBar();
    ((Control) this).SuspendLayout();
    this.m_cancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_cancel, "m_cancel");
    this.m_cancel.Name = "m_cancel";
    this.m_cancel.UseVisualStyleBackColor = true;
    this.m_cancel.Click += new EventHandler(this.m_cancel_Click);
    componentResourceManager.ApplyResources((object) this.m_progressBar, "m_progressBar");
    ((Control) this.m_progressBar).Name = "m_progressBar";
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Form) this).CancelButton = (IButtonControl) this.m_cancel;
    ((Form) this).ControlBox = false;
    ((Control) this).Controls.Add((Control) this.m_progressBar);
    ((Control) this).Controls.Add((Control) this.m_cancel);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Control) this).Name = nameof (CUiC3DProgressBarForm);
    ((Form) this).Shown += new EventHandler(this.CUiC3DProgressBarForm_Shown);
    ((Form) this).FormClosing += new FormClosingEventHandler(this.CUiC3DProgressBarForm_FormClosing);
    ((Control) this).ResumeLayout(false);
  }

  internal delegate void CUiC3DProgressBarForm_ProcessCanceledEventHandler(
    object sender,
    EventArgs args);

  internal delegate void CUiC3DProgressBarForm_StartProcessEventHandler(
    object sender,
    EventArgs args);
}
